
import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/home_form_bean.dart';
import 'package:flutter/material.dart';
import 'work_item_widget.dart';
import '../bean/ui_const_bean.dart';
import '../bean/work_home_bean.dart';


class WorkWarpWidget extends StatelessWidget {

  final HomeFormBean            homeFormBean;
  final UpdateModuleListBean    updateModuleBean;
  WorkWarpWidget(this.updateModuleBean,this.homeFormBean);

  @override
  Widget build(BuildContext context) {
    return buildWarpWidget(context);
  }

  Widget buildWarpWidget(BuildContext context) {

    double widgetW = MediaQuery.of(context).size.width - 2*UIConstBean.LRSpace - 2*UIConstBean.InnerLRSpace;
    double space = (widgetW - 2*UIConstBean.LRSpace - 2*UIConstBean.InnerLRSpace - 3*UIConstBean.FormItemWH)/2.0;

    return Container(
      width:  widgetW,
      color: Colors.white,
      child: Wrap(
        spacing: space, // 主轴(水平)方向间距
        runSpacing: 12.0, // 纵轴（垂直）方向间距
        direction: Axis.horizontal,
        alignment: WrapAlignment.start,
        children: _buildItemWidgets(),
      ),
    );
  }

  List<Widget>_buildItemWidgets() {
    List<Widget> results =  List<Widget>();
    if(homeFormBean == null) {
      for(int i = 0; i < 6; i++){
        results.add(WorkItemWidget('','-'));
      }
    } else {
      for(int i = 0; i < homeFormBean.list.length; i++){
        if(i > 5) break;
        FormItemBean itemBean = homeFormBean.list[i];
        results.add(WorkItemWidget(itemBean.title,itemBean.amount.toString()));
      }
    }
    return results;
  }
}

